cmake_minimum_required(VERSION 2.8.7)
project(libswiftnav)

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

# Setup flags for Code Coverage build mode
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage" CACHE STRING
    "Flags used by the C++ compiler for building with code coverage."
    FORCE )
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} --coverage" CACHE STRING
    "Flags used by the C compiler for building with code coverage."
    FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
    "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage" CACHE STRING
    "Flags used for linking binaries with code coverage."
    FORCE )
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage" CACHE STRING
    "Flags used by the shared libraries linker during builds with code coverage."
    FORCE )
mark_as_advanced(
    CMAKE_CXX_FLAGS_COVERAGE
    CMAKE_C_FLAGS_COVERAGE
    CMAKE_EXE_LINKER_FLAGS_COVERAGE
    CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
# Update the documentation string of CMAKE_BUILD_TYPE for GUIs
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
  "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
   FORCE )

# Set project version using Git tag and hash.
execute_process(
  COMMAND git describe --dirty --tags --always
  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  RESULT_VARIABLE GIT_VERSION_FOUND
  ERROR_QUIET
  OUTPUT_VARIABLE GIT_VERSION
  OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_VERSION_FOUND)
  set(VERSION "unknown")
else (GIT_VERSION_FOUND)
  set(VERSION ${GIT_VERSION})
endif (GIT_VERSION_FOUND)

# Set project version explicitly for release tarballs.
#set(VERSION foo)

message(STATUS "libswiftnav version: ${VERSION}")

cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Some compiler options used globally
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-strict-prototypes -Wno-unknown-warning-option -Werror -std=gnu99 ${CMAKE_C_FLAGS}")

if (NOT CMAKE_CROSSCOMPILING)
  # Detect and use optimised compiler flags for the host architecture,
  # this is specific to x86 family CPUs.
  include(cmake/OptimizeForArchitecture.cmake)
  OptimizeForArchitecture()
  message(STATUS "Adding architecture flags: ${Vc_ARCHITECTURE_FLAGS}")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Vc_ARCHITECTURE_FLAGS}")
endif ()

add_subdirectory(clapack-3.2.1-CMAKE)
add_subdirectory(CBLAS)
add_subdirectory(plover)
add_subdirectory(libfec)
add_subdirectory(src)
add_subdirectory(docs)
add_subdirectory(tests)

# Must match setting inside Doxyfile
set(DOXYGEN_WARNINGS "docs/doxygen_warnings.txt")
set(ALLOWED_DOXYGEN_WARNINGS ${PROJECT_SOURCE_DIR}/checks/allowed_doxygen_warnings.txt)

# TODO add srcs dependency
add_custom_target(check-doxygen 
  COMMAND diff ${ALLOWED_DOXYGEN_WARNINGS} ${DOXYGEN_WARNINGS}
  DEPENDS docs swiftnav-static)

add_custom_target(check-style DEPENDS check-doxygen checkpatch)
